package cn.wizzer.app.web.modules.controllers.platform.user.chat.group;

import cn.wizzer.app.user.modules.models.enums.MsgTypeEnum;
import cn.wizzer.app.user.modules.models.enums.OprTypeEnum;
import cn.wizzer.app.user.modules.services.GroupRecordService;
import cn.wizzer.framework.util.Result;
import com.alibaba.dubbo.config.annotation.Reference;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.log.Log;
import org.nutz.log.Logs;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.Param;

@IocBean
@At("/platform/user/group/record")
public class GroupRecordController {
    private static final Log log = Logs.get();

    @Inject
    @Reference
    private GroupRecordService groupRecordService;

    @At("/")
    @Ok("beetl:/platform/user/chat/group/record.html")
    @RequiresPermissions("user.group.record")
    public void index() {
    }

    /**
     * 查询（分页）
     *
     * @return Object
     */
    @At
    @Ok("json:full")
    @RequiresPermissions("user.group.record")
    public Object data(@Param("groupName") String groupName,
                       @Param("userKeyword") String userKeyword,
                       @Param("searchDate") String[] searchDate,
                       @Param("msgType") MsgTypeEnum msgType,
                       @Param("oprType") OprTypeEnum oprType,
                       @Param("pageNumber") int pageNumber,
                       @Param("pageSize") int pageSize) {
        return Result.success().addData(groupRecordService.listPage(pageNumber, pageSize, groupName, userKeyword, searchDate, msgType, oprType));
    }

    /**
     * @return Object
     */
    @At
    @Ok("json:full")
    @RequiresPermissions("user.group.record.delete")
    public Object del(String id) {
        // 红包记录不能删除 todo
        groupRecordService.delete(id);
        return Result.success();
    }

}
